﻿using SUNRPA.CONTROLS.IMPL.domain.attrubutes;
using SUNRPA.CONTROLS.IMPL.domain.constant;
using SUNRPA.CONTROLS.IMPL.domain.flowRunningVar;
using SUNRPA.CONTROLS.IMPL.util;
using System.Collections.Concurrent;
using System.Globalization;
using System.Windows.Data;

namespace SUNRPA.CONTROLS.IMPL.domain.flowItemParam {
    [Serializable]
    [VarFieldName("OutVarName")]
    public class OpenWebPageNParam:BaseParam {
        private string url = "";
        //google 0，IE 1， edge 2
        private BrowserType browType = BrowserType.GOOGLE;
        private string outVarName = "webPage";
        private bool waitWebPageLoad = true;
        private string loadExpireTime = "20";
        //加载超时后处理方式0执行错误处理、1停止加载
        private int expireDealType = 0;
        private string browserPath = "";
        public string Url {
            get => url; 
            set { 
                url = value;
                NotifyPropertyChanged("Url");
            }  
        }

        public BrowserType BrowType {
            get => browType; 
            set {
                browType = value;
                NotifyPropertyChanged("BrowserType");
            }  
        }
        public string OutVarName {
            get => outVarName; 
            set { 
                outVarName = value;
                NotifyPropertyChanged("OutVarName");
            }  
        }
        public bool WaitWebPageLoad {
            get => waitWebPageLoad; 
            set { 
                waitWebPageLoad = value;
                NotifyPropertyChanged("WaitWebPageLoad");
            }
}
        public string LoadExpireTime {
            get => loadExpireTime; 
            set { 
                loadExpireTime = value;
                NotifyPropertyChanged("LoadExpireTime");
            }  
        }

        public int ExpireDealType {
            get => expireDealType; 
            set { 
                expireDealType = value;
                NotifyPropertyChanged("ExpireDealType");
            }  
        }

        public string BrowserPath {
            get => browserPath; 
            set { 
                browserPath = value;
                NotifyPropertyChanged("BrowserPath");
            }  
        }
        public string GetTranslateBrowType() {
            switch(this.browType) {
                case BrowserType.GOOGLE:
                    return "GOOGLE浏览器";
                case BrowserType.IE:
                    return "IE浏览器";
                case BrowserType.EDGE:
                    return "Edge浏览器";
                default : return "GOOGLE浏览器";
            }
        }

        public override void SetLatestVarName(ConcurrentDictionary<string, ConcurrentDictionary<string, RPAVariableDefineWrapper>> globleData) {
            this.outVarName = this.GetLatestName(this.outVarName, globleData);
        }
    }

    public class BrowTypeConverter : IValueConverter {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
            return (int)value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            return Enum.Parse(typeof(BrowserType), value.ToString());
        }
    }
}
